/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.articles.importFromLn.cli;

import cz.mzk.kramerius.articles.importFromLn.krameriusAccess.Repository;
import cz.mzk.kramerius.commons.DatastreamId;
import cz.mzk.kramerius.commons.PidList;
import cz.mzk.kramerius.commons.PropertyLoader;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Martin Řehánek <rehan at mzk.cz>
 */
class UdateDatastreamsAction implements Action {

    private static final Logger logger = Logger.getLogger(UdateDatastreamsAction.class.getName());
    private final Repository rep;
    private final DatastreamId dsId;
    private final PidList pidList;
    private final String updaterClassName;

    public UdateDatastreamsAction(PropertyLoader properties, File pidListFile, String dsId, String updaterClassName) throws IOException {
        this.rep = Repository.instanceOf(properties);
        this.dsId = new DatastreamId(dsId);
        this.pidList = new PidList(pidListFile);
        this.updaterClassName = updaterClassName;
    }

    @Override
    public void run() {
        for (String pid : pidList.content()) {
            logger.log(Level.INFO, "updating datastream {0} of object {1}", new Object[]{dsId.toString(), pid});
            rep.updateArticleDatastream(pid, dsId, updaterClassName);
        }
    }
}
